package com.chagee.store.operation.server.event.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chagee.store.operation.server.entity.OperateRecordDO;
import com.chagee.store.operation.server.event.dao.OperateRecordMapper;
import com.chagee.store.operation.server.model.param.QueryOperateRecordParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 操作记录保存
 */
@Slf4j
@Service
public class OperateRecordBaseService extends ServiceImpl<OperateRecordMapper, OperateRecordDO> {

	// 评价配置操作日志
	public static final Integer RECORD_TYPE_3 = 3;
	// 闭店任务操作记录
	public static final Integer RECORD_TYPE_2 = 2;
	// 门店管理档案类型
	public static final Integer RECORD_TYPE = 1;
	// 开业任务操作记录
	public static final Integer RECORD_TYPE_0 = 0;

	// 操作类型
	public static final String INSERT_OPERATE_TYPE = "insert";
	public static final String UPDATE_OPERATE_TYPE = "update";
	public static final String DELETE_OPERATE_TYPE = "delete";

	/**
	 * 新增类型操作记录
	 */
	public void addInsertOptRecord(OperateRecordDO operateRecordDO) {
		operateRecordDO.setOperateType(INSERT_OPERATE_TYPE);
		operateRecordDO.setRecordType(RECORD_TYPE_3);
		save(operateRecordDO);
	}

	/**
	 * 修改类型操作记录
	 */
	public void addUpdateOptRecord(OperateRecordDO operateRecordDO) {
		operateRecordDO.setOperateType(UPDATE_OPERATE_TYPE);
		operateRecordDO.setRecordType(RECORD_TYPE_3);
		save(operateRecordDO);
	}

	public Page<OperateRecordDO> queryRecordPage(QueryOperateRecordParam param,Page<OperateRecordDO> page) {
		QueryWrapper<OperateRecordDO> query = Wrappers.query();
		query.eq("delete_flag", 0);
		query.eq("record_type", param.getRecordType());
		query.orderByDesc("create_time");
		return baseMapper.selectPage(page, query);
	}
}
